﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

namespace Genuilder.Extensibility.Tests
{
	[TestClass]
	public class FileMementoRepositoryTest
	{
		[TestMethod]
		public void CanSaveMementos()
		{
			FileInfo mementoFile = new FileInfo("mementoFile");
			FileCodeItemMementoRepository repository = new FileCodeItemMementoRepository(mementoFile);
			var mementos = GetMementos();
			repository.SaveCodeItemMementos(mementos);
			mementoFile.Refresh();
			Assert.IsTrue(mementoFile.Exists);
		}

		[TestMethod]
		public void CanSaveThenLoadMementos()
		{
			FileInfo mementoFile = new FileInfo("mementoFileAndLoad");
			FileCodeItemMementoRepository repository = new FileCodeItemMementoRepository(mementoFile);
			var mementos = GetMementos();
			repository.SaveCodeItemMementos(mementos);
			var loadedMementos = repository.LoadCodeItemMementos();
			Assert.AreEqual(mementos.Count(), loadedMementos.Count());
		}

		private IEnumerable<DirectoryCodeRepository.CodeItemMemento> GetMementos()
		{
			yield return new DirectoryCodeRepository.CodeItemMemento()
			{
				
				FileName = "memento1",
				LastModified = DateTime.Now
			};
			yield return new DirectoryCodeRepository.CodeItemMemento()
			{
			
				FileName = "memento2",
				LastModified = DateTime.Now
			};
		}
	}

}
